package com.ssmr.demo.service;

import com.ssmr.demo.dao.TPurchaseRecordMapper;
import com.ssmr.demo.entity.TPurchaseRecord;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.CachePut;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

@Service
public class TPurchaseRecordServiceImpl implements TPurchaseRecordService {
    @Resource
    private TPurchaseRecordMapper tPurchaseRecordMapper;

    @Override
    @Transactional
    @CacheEvict(value = "redisCacheManager", key = "'redis_cache_purchaserecord_'+#idtPurchaseRecord")
    public int deleteByPrimaryKey(Integer idtPurchaseRecord) {
        return tPurchaseRecordMapper.deleteByPrimaryKey(idtPurchaseRecord);
    }

    @Override
    @Transactional
    public int insert(TPurchaseRecord record) {
        return tPurchaseRecordMapper.insert(record);
    }

    @Override
    @Transactional
    @CachePut(value = "redisCacheManager", key = "'redis_cache_purchaserecord_'+#record.idtPurchaseRecord")
    public TPurchaseRecord insertAndReturn(TPurchaseRecord record) {
        tPurchaseRecordMapper.insert(record);
        return record;
    }

    @Override
    @Transactional
    @Cacheable(value = "redisCacheManager", key = "'redis_cache_purchaserecord_'+#idtPurchaseRecord")
    public TPurchaseRecord selectByPrimaryKey(Integer idtPurchaseRecord) {
        return tPurchaseRecordMapper.selectByPrimaryKey(idtPurchaseRecord);
    }

    @Override
    @Transactional
    public List<TPurchaseRecord> selectAll() {
        return tPurchaseRecordMapper.selectAll();
    }

    @Override
    @Transactional
    public int updateByPrimaryKey(TPurchaseRecord record) {
        return tPurchaseRecordMapper.updateByPrimaryKey(record);
    }

    @Override
    @Transactional
    @CachePut(value = "redisCacheManager", key = "'redis_cache_purchaserecord_'+#record.idtPurchaseRecord")
    public TPurchaseRecord updateByPrimaryKeyAndReturn(TPurchaseRecord record) {
        tPurchaseRecordMapper.updateByPrimaryKey(record);
        return record;
    }
}
